package com.olap.starter.common.vo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class SaveMainAndSubTable extends BaseParameter {

    /**
     {
     dbName:'',
     tableName:'',
     subTableName:'',
     mianColumnAndValueMap:{k:v},
     mainGenIdMap:{k:v} //如果没有 可以忽略
     mainTableKey:[],
     subColumnAndValueList:[{k:v}],
     subTableKey:[],
     subForeignKey:{主表key:sub表外键key }
     */

    //主表列
    Map<String,Object> mianColumnAndValueMap;
    //生成IDMap
    Map<String,String> mainGenIdMap;
    //根据这个key进行判断是否更新
    private List<String> mainTableKey;
    //子表表名
    private String subTableName;
    //子表list列
    List<Map<String,Object>> subColumnAndValueList;
    //生成IDMap
    Map<String,String> subGenIdMap;
    //根据这个key进行判断是否更新
    private List<String> subTableKey;
    //子表删除操作
    private Map<String,Object> subDeleteMapWhere;
    //自动赋值  外键
    private Map<String,String> subForeignKey;
    String createBy;
    String updateBy;

    public SaveParameter getMainTable(){
        SaveParameter saveParameter = new SaveParameter();
        saveParameter.setGenIdMap(this.mainGenIdMap);
        saveParameter.setTableName(this.tableName);
        saveParameter.setDbType(this.dbType);
        saveParameter.setColumnAndValueMap(this.mianColumnAndValueMap);
        return saveParameter;
    }

    public List<SaveParameter> getSubTable(){
        List<SaveParameter> subColumnAndValueList = new ArrayList<>();
        for (Map<String, Object> columnAndValueMap : this.subColumnAndValueList) {
            SaveParameter saveParameter = new SaveParameter();
            saveParameter.setTableName(this.subTableName);
            saveParameter.setGenIdMap(this.subGenIdMap);
            saveParameter.setColumnAndValueMap(columnAndValueMap);
            saveParameter.setDbType(this.dbType);
            subColumnAndValueList.add(saveParameter);
        }
        return subColumnAndValueList;
    }
}
